﻿using Pipes.Aras;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Pipes.UnitTest
{   
  /// <summary>
  ///This is a test class for SelectStatementReaderTest and is intended
  ///to contain all SelectStatementReaderTest Unit Tests
  ///</summary>
  [TestClass()]
  public class SelectStatementReaderTest
  {


    private TestContext testContextInstance;

    /// <summary>
    ///Gets or sets the test context which provides
    ///information about and functionality for the current test run.
    ///</summary>
    public TestContext TestContext
    {
      get
      {
        return testContextInstance;
      }
      set
      {
        testContextInstance = value;
      }
    }

    #region Additional test attributes
    // 
    //You can use the following additional attributes as you write your tests:
    //
    //Use ClassInitialize to run code before running the first test in the class
    //[ClassInitialize()]
    //public static void MyClassInitialize(TestContext testContext)
    //{
    //}
    //
    //Use ClassCleanup to run code after all tests in a class have run
    //[ClassCleanup()]
    //public static void MyClassCleanup()
    //{
    //}
    //
    //Use TestInitialize to run code before running each test
    //[TestInitialize()]
    //public void MyTestInitialize()
    //{
    //}
    //
    //Use TestCleanup to run code after each test has run
    //[TestCleanup()]
    //public void MyTestCleanup()
    //{
    //}
    //
    #endregion


    /// <summary>
    ///A test for GetColumns
    ///</summary>
    [TestMethod()]
    public void GetColumnsTestSimple()
    {
      string input = "first,second,,,third,fourth";
      var expected = new List<SelectColumn>();
      expected.Add(new SelectColumn("first"));
      expected.Add(new SelectColumn("second"));
      expected.Add(new SelectColumn("third"));
      expected.Add(new SelectColumn("fourth"));

      var actual = SelectStatementReader.GetColumns(input).ToArray();
      CollectionAssert.AreEqual(expected, actual);
    }

    [TestMethod()]
    public void GetColumnsTestComplex()
    {
      string input = "first,second(id,name),third(a,b,c),fourth";
      var expected = new List<SelectColumn>();
      expected.Add(new SelectColumn("first"));
      expected.Add(new SelectColumn("second", "id,name"));
      expected.Add(new SelectColumn("third", "a,b,c"));
      expected.Add(new SelectColumn("fourth"));

      var actual = SelectStatementReader.GetColumns(input).ToArray();
      CollectionAssert.AreEqual(expected, actual);
    }

    [TestMethod()]
    public void GetColumnsTestWeirdSituations()
    {
      string input = "first,second(id,name)and,third(thing)(a,b,c),fourth";
      var expected = new List<SelectColumn>();
      expected.Add(new SelectColumn("first"));
      expected.Add(new SelectColumn("second", "(id,name)and"));
      expected.Add(new SelectColumn("third(thing)", "a,b,c"));
      expected.Add(new SelectColumn("fourth"));

      var actual = SelectStatementReader.GetColumns(input).ToArray();
      CollectionAssert.AreEqual(expected, actual);
    }
  }
}
